package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PServerVo;
import com.ruoyi.system.domain.bo.PServerBo;
import com.ruoyi.system.service.IPServerService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 联系客服Controller
 *
 * @author ruoyi
 * @date 2022-07-28
 */
@Validated
@Api(value = "联系客服控制器", tags = {"联系客服管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/server")
public class PServerController extends BaseController {

    private final IPServerService iPServerService;

    /**
     * 查询联系客服列表
     */
    @ApiOperation("查询联系客服列表")
    @SaCheckPermission("system:server:list")
    @GetMapping("/list")
    public TableDataInfo<PServerVo> list(PServerBo bo, PageQuery pageQuery) {
        return iPServerService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出联系客服列表
     */
    @ApiOperation("导出联系客服列表")
    @SaCheckPermission("system:server:export")
    @Log(title = "联系客服", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PServerBo bo, HttpServletResponse response) {
        List<PServerVo> list = iPServerService.queryList(bo);
        ExcelUtil.exportExcel(list, "联系客服", PServerVo.class, response);
    }

    /**
     * 获取联系客服详细信息
     */
    @ApiOperation("获取联系客服详细信息")
    @SaCheckPermission("system:server:query")
    @GetMapping("/{id}")
    public R<PServerVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPServerService.queryById(id));
    }

    /**
     * 新增联系客服
     */
    @ApiOperation("新增联系客服")
    @SaCheckPermission("system:server:add")
    @Log(title = "联系客服", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PServerBo bo) {
        return toAjax(iPServerService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改联系客服
     */
    @ApiOperation("修改联系客服")
    @SaCheckPermission("system:server:edit")
    @Log(title = "联系客服", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PServerBo bo) {
        return toAjax(iPServerService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除联系客服
     */
    @ApiOperation("删除联系客服")
    @SaCheckPermission("system:server:remove")
    @Log(title = "联系客服", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPServerService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
